<template>
  <div class="container">
    <div class="news_left"></div>
    <section class="news-container">
      <div
        class="news-card"
        v-for="(item, index) in newList"
        :key="item.id || index"
        @click="handleClick(item)"
      >
        <div class="news-timestamp">
          <div class="news-date">
            {{ formatDate(item.update_time, 0) }}
          </div>
          <div class="news-time">
            {{ formatDate(item.update_time, 1) }}
          </div>
        </div>

        <div class="news-content">
          <div class="news-image">
            <img
              :src="item.thumb_url"
              :alt="item.title"
              class="image-cover"
            />
          </div>
          <div class="news-details">
            <h3 class="news-title">{{ item.title }}</h3>
            <p class="news-summary">{{ item.digest }}</p>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import moment from "moment";

export default {
  props: {
    newList: {
      type: Array,
      default: () => [],
    },
  },
 
  methods: {
    formatDate(date, type) {
      const timestamp = +date * 1000;
      return type === 1
        ? moment(timestamp).format("HH:mm")
        : moment(timestamp).format("YYYY-MM-DD");
    },

    handleClick(item) {
      window.open(item.url, "_blank");
    },
  },
};
</script>

<style lang="less" scoped>
// @import "@/styles/variables.less"; // 假设有变量文件

.news-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

.news-card {
  display: flex;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  cursor: pointer;
  position: relative;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, #4facfe 0%, #00f2fe 100%);
  }

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 115, 255, 0.15);

    .news-title {
      color: #0066ff;
    }

    .news-image img {
      transform: scale(1.05);
    }
  }
}

.news-timestamp {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 90px;
  padding: 16px 12px;
  background: rgba(249, 250, 251, 0.6);
  border-right: 1px solid #f0f2f5;
}

.news-date {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: -0.3px;
}

.news-time {
  font-size: 14px;
  color: #7a7a7a;
  margin-top: 4px;
}

.news-content {
  display: flex;
  padding: 20px;
  gap: 20px;
  width: 100%;
}

.news-image {
  width: 120px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
  }
}

.news-details {
  flex: 1;
  min-width: 0;
}

.news-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  color: #222;
  margin-bottom: 8px;
  transition: color 0.2s ease;
  .text-ellipsis(2); // 多行省略混合函数
}

.news-summary {
  font-size: 14px;
  line-height: 1.5;
  color: #666;
  .text-ellipsis(3); // 多行省略混合函数
}

// 多行文本省略混合函数
.text-ellipsis(@lines) {
  display: -webkit-box;
  -webkit-line-clamp: @lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .news-container {
    padding: 15px;
  }

  .news-card {
    flex-direction: column;

    &::before {
      width: 100%;
      height: 4px;
    }
  }

  .news-timestamp {
    flex-direction: row;
    justify-content: space-between;
    padding: 12px 20px;
    border-right: none;
    border-bottom: 1px solid #f0f2f5;
  }

  .news-content {
    flex-direction: column;
    padding: 16px;
    gap: 15px;
  }

  .news-image {
    width: 100%;
    height: 160px;
  }
}
</style>